package com.lingshi.shopping_manager_api.controller;

import com.lingshi.shopping.entity.Category;
import com.lingshi.shopping.result.BaseResult;
import com.lingshi.shopping.service.CategoryService;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.web.bind.annotation.*;

/**
 * 广告管理
 */
@RestController
@RequestMapping("/category")
public class CategoryController {

    @DubboReference
    private CategoryService categoryService;

    /**
     * 新增广告
     * @param category 广告对象
     * @return
     */
    @PostMapping("/add")
    public BaseResult add(@RequestBody Category category) {
        categoryService.add(category);
        return BaseResult.success();
    }

    /**
     * 修改广告
     * @param category 广告对象
     * @return
     */
    @PutMapping("/update")
    public BaseResult update(@RequestBody Category category) {
        categoryService.update(category);
        return BaseResult.success();
    }

    /**
     * 修改广告状态
     * @param id 广告id
     * @param status  0 关闭 1 启用
     * @return
     */
    @PutMapping("/updateStatus")
    public BaseResult updateStatus(Long id, Integer status) {
        categoryService.updateStatus(id, status);
        return BaseResult.success();
    }

    /**
     * 删除广告
     * @param ids 广告id
     * @return
     */
    @DeleteMapping("/delete")
    public BaseResult delete(Long[] ids) {
        categoryService.delete(ids);
        return BaseResult.success();
    }

    /**
     * 分页查询
     * @param page 页码
     * @param size 每页条数
     * @return 广告员分页对象
     */
    @GetMapping("/search")
    public BaseResult search(@RequestParam(defaultValue = "1") Integer page,
            @RequestParam(defaultValue = "10") Integer size) {
        return BaseResult.success(categoryService.search(page,size));
    }

    /**
     * 根据id查询广告
     * @param id 广告id
     * @return 广告员对象
     */
    @GetMapping("/findById")
    public BaseResult findById(Long id) {
        return BaseResult.success(categoryService.findById(id));
    }


   
}
